package com.gk.controller;

import com.gk.security.JwtAuthenticationToken;
import com.gk.utils.RedisUtil;
import com.gk.utils.SecurityUtils;
import com.gk.vo.LoginBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @description:登录方法
 * @author: godkey
 * @Date: 2020/12/16 11:35
 */
@RestController
public class LoginController {

    @Autowired
    private AuthenticationManager authenticationManager;
    @Autowired
    private RedisUtil redisUtil;
    /**
     * 登录接口
     */
    @PostMapping(value = "/login")
    public JwtAuthenticationToken login(@RequestBody LoginBean loginBean, HttpServletRequest request) throws IOException {
        String username = loginBean.getUsername();
        String password = loginBean.getPassword();

        // 系统登录认证
        JwtAuthenticationToken token = SecurityUtils.login(request, username, password, authenticationManager);
        return token;
    }

//    /**
//     * 登录退出
//     */
//    @PostMapping(value = "/loginOut")
//    public void loginOut(){
//        SecurityContextHolder.clearContext();
//    }
}
